package com.shop.mms_client.api;

import android.net.Uri;
import okhttp3.MediaType;
import okhttp3.MultipartBody;
import okhttp3.RequestBody;
import retrofit2.Call;
import java.io.File;
import com.shop.mms_client.model.DetectionResult;
import com.shop.mms_client.model.MessageRequest;

public class ApiManager {
    private static ApiManager instance;
    private final ApiService apiService;
    
    private ApiManager() {
        apiService = RetrofitClient.getClient().create(ApiService.class);
    }
    
    public static synchronized ApiManager getInstance() {
        if (instance == null) {
            instance = new ApiManager();
        }
        return instance;
    }
    
    public Call<DetectionResult> detectText(String text, String sender) {
        return apiService.detectText(new MessageRequest(text, sender));
    }
    
    public Call<DetectionResult> detectMms(String text, String sender, File imageFile) {
        RequestBody textBody = RequestBody.create(MediaType.parse("text/plain"), text);
        RequestBody senderBody = RequestBody.create(MediaType.parse("text/plain"), sender);
        
        RequestBody imageRequestBody = RequestBody.create(
            MediaType.parse("image/*"),
            imageFile
        );
        
        MultipartBody.Part imagePart = MultipartBody.Part.createFormData(
            "image",
            imageFile.getName(),
            imageRequestBody
        );
        
        return apiService.detectMms(textBody, senderBody, imagePart);
    }
} 